﻿<Window
  x:Class="Jerry.DroidBuilder.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:loc="clr-namespace:Jerry.DroidBuilder"
  xmlns:ext="clr-namespace:Jerry.DroidBuilder.Extensions"
  xmlns:ctrl="clr-namespace:Jerry.DroidBuilder.Controls"
  xmlns:local="clr-namespace:Jerry.DroidBuilder"
  Width="800"
  Height="640"
  Icon="App.ico"
  Background="#FF333333"
  Title="Droid Builder v0.1 Beta"
  WindowStartupLocation="CenterScreen"
  DataContext="{Binding ViewModel, RelativeSource={RelativeSource Self}}"
  IsVisibleChanged="OnIsVisibleChanged">
  <Window.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/DroidBuilder;component/Templates/Templates.xaml"/>
        <ResourceDictionary>
          <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
        </ResourceDictionary>
      </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Window.Resources>
  <Grid>
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="Auto"/>
      <RowDefinition Height="*"/>
      <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <Grid Grid.Row="0">
      <Menu>
        <MenuItem Header="{loc:Localize Menu_File}">
          <MenuItem Header="{loc:Localize Menu_Open}" Command="{Binding OpenCommand}"/>
        </MenuItem>
        <MenuItem Header="{loc:Localize Menu_Tools}">
          <MenuItem Header="{loc:Localize Menu_Tools_SignSingle}" Command="{Binding SignCommand}"/>
          <MenuItem Header="{loc:Localize Menu_Tools_SignAll}" Command="{Binding CurrentModel.SignAllCommand}" IsEnabled="{Binding IsRomView, Converter={StaticResource BooleanToVisibilityConverter}}"/>
          <MenuItem Header="{loc:Localize Menu_Tools_UpdateReference}" Command="{Binding UpdateReferenceCommand}"/>
        </MenuItem>
        <MenuItem Header="{loc:Localize Menu_Device}">
          <MenuItem Header="{loc:Localize Menu_Device_Reboot}" Command="{Binding RebootCommand}"/>
          <MenuItem Header="{loc:Localize Menu_Device_Reboot_Recovery}" Command="{Binding RebootCommand}" CommandParameter="recovery"/>
          <MenuItem Header="{loc:Localize Menu_Device_Reboot_Bootloader}" Command="{Binding RebootCommand}" CommandParameter="bootloader"/>
        </MenuItem>
        <MenuItem Header="{loc:Localize Menu_Help}">
          <MenuItem Header="{loc:Localize Menu_Help_How}"/>
          <Separator/>
          <MenuItem Header="{loc:Localize Menu_Help_About}"/>
        </MenuItem>
      </Menu>
      <TextBlock Foreground="#F6F6F6" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,20,0">
        <Run Text="{loc:Localize Visit_Title}"/>
        <Hyperlink NavigateUri="http://www.doocy.com/" Click="OnLinkClick">
          <Run Text="{loc:Localize Visit_ProjectHome}"/>
        </Hyperlink>
        <Hyperlink NavigateUri="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&amp;business=jerryes%40gmail%2ecom&amp;lc=C2&amp;item_name=Droid%20Builder&amp;currency_code=USD&amp;bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHostedGuest" Click="OnLinkClick">
          <Run Text="{loc:Localize Visit_Donate}"/>
        </Hyperlink>
      </TextBlock>
    </Grid>
    <Grid Grid.Row="1">
      <ToolBarTray SnapsToDevicePixels="True">
        <ToolBar>
          <Button Command="{Binding CurrentModel.BuildCommand}" IsEnabled="{Binding CurrentModel.SupportBuild, FallbackValue=False}">
            <StackPanel Orientation="Horizontal" Margin="3,1,8,0">
              <Image Source="Images/build.png" Width="24" Height="24" Margin="0,0,3,0"/>
              <TextBlock Text="{loc:Localize Menu_Build}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
        </ToolBar>
        <ToolBar>
          <Button Command="{Binding CurrentModel.DeodexCommand}" IsEnabled="{Binding CurrentModel.SupportDeodex, FallbackValue=False}">
            <StackPanel Orientation="Horizontal" Margin="3,1,8,0">
              <Image Source="Images/deodex.png" Width="24" Height="24" Margin="0,0,0,0"/>
              <TextBlock Text="{loc:Localize Menu_Deodex}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
          <Button Command="{Binding CurrentModel.DexoptCommand}" IsEnabled="{Binding CurrentModel.SupportDeodex, FallbackValue=False}" Visibility="Collapsed">
            <StackPanel Orientation="Horizontal" Margin="3,1,8,0">
              <Image Source="Images/dexopt.png" Width="24" Height="24" Margin="0,0,0,0"/>
              <TextBlock Text="{loc:Localize Menu_Dexopt}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
          <Button Command="{Binding CurrentModel.ZipAlignCommand}" IsEnabled="{Binding CurrentModel.SupportZipAlign, FallbackValue=False}">
            <StackPanel Orientation="Horizontal" Margin="3,1,8,0">
              <Image Source="Images/zipalign.png" Width="24" Height="24" Margin="0,0,0,0"/>
              <TextBlock Text="{loc:Localize Menu_ZipAlign}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
          <Button IsEnabled="{Binding CurrentModel.SupportTranslate}">
            <StackPanel Orientation="Horizontal" Margin="3,1,8,0">
              <Image Source="Images/translate.png" Width="24" Height="24" Margin="0,0,3,0"/>
              <TextBlock Text="{loc:Localize Menu_Translate}" VerticalAlignment="Center"/>
            </StackPanel>
          </Button>
        </ToolBar>
        <ToolBar>
          <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="3,0,3,0">
            <TextBlock Text="{loc:Localize Menu_ROM}" Foreground="#FFFFFFFF"/>
            <ComboBox
              Width="150"
              ItemsSource="{Binding Directories}"
              ext:CommandExtension.Command="{Binding ChangeDirectoryCommand}"
              ext:CommandExtension.CommandParameter="{Binding SelectedItem, RelativeSource={RelativeSource Self}}"
              ext:CommandExtension.RoutedEvent="Selector.SelectionChanged"/>
          </StackPanel>
        </ToolBar>
        <ToolBar Visibility="{Binding IsRomView, Converter={StaticResource BooleanToVisibilityConverter}}">
          <StackPanel Orientation="Horizontal" VerticalAlignment="Center" Margin="3,0,3,0">
            <TextBlock Text="{loc:Localize Menu_Patch}" Foreground="#FFFFFFFF"/>
            <ComboBox x:Name="m_patchList" Width="120" ItemsSource="{Binding Patches}"/>
          </StackPanel>
          <Button
            Content="{loc:Localize Menu_Apply}"
            IsEnabled="{Binding SelectedItems.Count, ElementName=m_patchList}"
            ext:CommandExtension.Command="{Binding ApplyPatchCommand}"
            ext:CommandExtension.CommandParameter="{Binding SelectedItem, ElementName=m_patchList}"
            ext:CommandExtension.RoutedEvent="ButtonBase.Click"
            />
        </ToolBar>
      </ToolBarTray>
    </Grid>
    <Grid Grid.Row="2">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
      </Grid.RowDefinitions>
      <Grid Grid.Row="0">
        <ListBox SelectedValue="{Binding CurrentModel, Mode=TwoWay}" SnapsToDevicePixels="True" ItemsSource="{Binding Models}" Margin="0,5,0,0" IsSynchronizedWithCurrentItem="True" Style="{DynamicResource TablikeListBoxStyle}" ItemTemplate="{DynamicResource OpenedFormItemTemplate}">
          <ListBox.ItemsPanel>
            <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
          </ListBox.ItemsPanel>
        </ListBox>
      </Grid>
      <Grid Grid.Row="1" Background="#FF595959" Opacity="{Binding Models.Count}">
        <ListBox Margin="5" ItemsSource="{Binding Models}" IsSynchronizedWithCurrentItem="True">
          <ListBox.Style>
            <Style TargetType="{x:Type ListBox}">
              <Setter Property="Background" Value="#00000000"/>
              <Setter Property="BorderBrush" Value="#FF000000"/>
              <Setter Property="BorderThickness" Value="0"/>
              <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
              <Setter Property="ItemsPanel">
                <Setter.Value>
                  <ItemsPanelTemplate>
                    <Grid/>
                  </ItemsPanelTemplate>
                </Setter.Value>
              </Setter>
              <Setter Property="ItemContainerStyle">
                <Setter.Value>
                  <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="Template">
                      <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListBoxItem}">
                          <Border x:Name="Bd" SnapsToDevicePixels="True">
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                          </Border>
                          <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="False">
                              <Setter Property="Visibility" Value="Collapsed"/>
                            </Trigger>
                          </ControlTemplate.Triggers>
                        </ControlTemplate>
                      </Setter.Value>
                    </Setter>
                  </Style>
                </Setter.Value>
              </Setter>
              <Setter Property="Template">
                <Setter.Value>
                  <ControlTemplate TargetType="{x:Type ListBox}">
                    <Border x:Name="Bd" SnapsToDevicePixels="True" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                      <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </Border>
                  </ControlTemplate>
                </Setter.Value>
              </Setter>
              <Style.Triggers>
                <DataTrigger Binding="{Binding Items.Count, RelativeSource={RelativeSource Self}}" Value="0">
                  <Setter Property="Visibility" Value="Collapsed"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </ListBox.Style>
        </ListBox>
      </Grid>
    </Grid>
    <Grid Grid.Row="3">
      <StatusBar>
        <!--<StatusBarItem DockPanel.Dock="Right" Content="M #1"/>
        <Separator DockPanel.Dock="Right"/>
        <StatusBarItem DockPanel.Dock="Right" Content="M #2"/>
        <Separator DockPanel.Dock="Right"/>-->
        <StatusBarItem Content="{Binding StatusInfo}"/>
      </StatusBar>
    </Grid>
    <Grid Grid.RowSpan="4" Background="Transparent" Visibility="{Binding IsLocked, Converter={StaticResource BooleanToVisibilityConverter}}">
      <Border Background="#80000000" BorderBrush="#A0000000" CornerRadius="5" Padding="35" HorizontalAlignment="Center"  VerticalAlignment="Center" BorderThickness="0,0,2,2">
        <StackPanel Width="180">
          <ProgressBar x:Name="m_progressBar" Height="10" Maximum="100" Value="35" IsIndeterminate="True" Margin="0,0,0,8"/>
          <TextBlock Text="{Binding StatusInfo}" ToolTip="{Binding StatusInfo}" ToolTipService.Placement="Relative" Foreground="White" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis"/>
        </StackPanel>
      </Border>
    </Grid>
  </Grid>
</Window>
